import JSEncrypt from "jsencrypt/bin/jsencrypt.min";

// 密钥对生成 http://web.chacuo.net/netrsakeypair

const publicKey =
  "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDO8kWNiaowodo6OTThfReZLIf3gmurDrmZv7hljTKy3ZC+p+5oCroPgzQmdvmh9ddOqOOzytpYc/tD/zHj7DqIo74RBSheeIQegfESH0H5Z9ahkSA4eHiL5TlIumGkB/lNbck5mPpOyMuJLli6Wr3A8kiL2dtJN7RqIVlpUjW1yQIDAQAB";

const privateKey =
  "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAM7yRY2JqjCh2jo5NOF9F5ksh/eCa6sOuZm/uGWNMrLdkL6n7mgKug+DNCZ2+aH1106o47PK2lhz+0P/MePsOoijvhEFKF54hB6B8RIfQfln1qGRIDh4eIvlOUi6YaQH+U1tyTmY+k7Iy4kuWLpavcDySIvZ20k3tGohWWlSNbXJAgMBAAECgYEAwg5/WEUCWY48hCKGyvexfEo8ycT7z7EEK/+TG283XnDUPWRd9CQy6z7+VR914QEWQEWxGDSdYRqJQO75yqAHFc+XMlyaaRiCI4T7Gj1EkpuGIFu11Hh7p2clAkoufJT08CFF4lEIAJP61fUp1Ko1x0G6lRb2erhF8LExH2BCvTECQQD3tdgeV7Qmz3YNBtGXEg8yyg25hPcqm6v+Zrv9Hym3r4mjtqaPrwry9aRWUF0bXPIe88qw9io6tT3u92/MkWB1AkEA1d8y+6pFksFosl9Y+ofm+WowQCN0VQGg7RtRU/g68JN1fayq6PV6rij/t2ux46UAdyd8t0IEMACdNdhbHhEVhQJBAI/hxTXitZaxfJ2Wb1lzuPZEXPJ8pGDQaXfszpb5ae7y/FzmtBrTjuWO/zTPmzVQqKaH7x0Y73CIZAARI5RMgR0CQGeEfh/TvZMX7D4R6nZw2zozzKDuyDrw69x4EXhMOPMC3KZ0sdDKKJQtogA8r0CZN810nmfxGyfE1FMgopG+ASUCQQDsJffhe44RfKM3saYRidWchuj0cwImwHhplXINCTsq5jdSdbKzcqkP4gly+S88I13mUi3V1zmf4tIW8SJ6+07S";

// 加密
export function encrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey); // 设置公钥
  return encryptor.encrypt(txt); // 对数据进行加密
}

// 解密
export function decrypt(txt) {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey); // 设置私钥
  return encryptor.decrypt(txt); // 对数据进行解密
}
